<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="/lib/layui/css/layui.css" rel="stylesheet"/>
    <link href="/css/common.css" rel="stylesheet"/>
    <title>编辑组织机构</title>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space10">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="layui-color-red">*</span>&nbsp;上级组织机构：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" type="text" name="parentName" lay-verify="required" placeholder="请输入上级组织机构" autocomplete="off" readonly>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="layui-color-red">*</span>&nbsp;组织机构名称：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" type="text" name="orgName" lay-verify="required" placeholder="请输入组织机构名称" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="layui-color-red">*</span>&nbsp;组织机构类型：</label>
                        <div class="layui-input-block">
                            <select id="orgType" name="orgType" lay-filter="orgType" lay-verify="required" title=""></select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="layui-color-red">*</span>&nbsp;排序：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" type="text" name="orderNum" lay-verify="required|number" placeholder="请输入排序" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="id">
                            <input type="hidden" name="parentId">
                            <button class="layui-btn" lay-filter="submitBtn" lay-submit data-url="/system/organization/saveOrUpdate.do">提交</button>
                            <button class="layui-btn layui-hide" type="button" id="submit">提交</button>
                            <button class="layui-btn layui-btn-primary" type="button" id="cancel">取消</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui/layui.all.js" charset="utf-8"></script>
<script src="/script/common.js" charset="utf-8"></script>
<script>
    var id = getRequestParams('id');
    var parentId = getRequestParams('parentId');

    layui.use(['baseUtil'], function () {
        var $ = layui.jquery,
            baseUtil = layui.baseUtil;

        $('input[name=id]').val(id);
        $('input[name=parentId]').val(parentId);

        if (isBlank(id)) {
            baseUtil.initDict('orgType', function (dictContent) {
                baseUtil.initSelect(dictContent, 'orgType', '2');
                if (isBlank(parentId)) {
                    //根目录添加
                    $('input[name=parentName]').val('根组织');
                } else {
                    //子目录添加
                    baseUtil.doPostData('/system/organization/findOne.do', { id: parentId }, function (data) {
                        $('input[name=parentName]').val(data.orgName);
                    });
                }
            });
        } else {
            baseUtil.initDict('orgType', function (dictContent) {
                var url = '/system/organization/findVoOne.do';
                var params = { id: id };
                var cols = [
                    { type: 'input', name: 'orgName' },
                    { type: 'select', name: 'orgType', dictContent: dictContent },
                    { type: 'input', name: 'orderNum' }
                ];
                if (isBlank(parentId)) {
                    //根目录编辑
                    $('input[name=parentName]').val('根组织');
                } else {
                    //子目录编辑
                    cols.push({ type: 'input', name: 'parentName' });
                }
                baseUtil.initFormData(url, params, cols);
            });
        }
    });
</script>
</body>
</html>
